package search;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/26-下午2:56
 * Since  :   1.0
 * Version:   1.0
 */
public class binarySearch {

    public static int binary(int [] arr,int start,int end,int findVal){
        if (start>end) {
            return -1;
        }
        int midIndex=(start+end)/2;
        int midVal=arr[midIndex];
        if (findVal>midVal){
          return   binary(arr,midIndex+1,end,findVal);
        }else if (findVal<midVal)

        {
           return binary(arr,start,midIndex-1,findVal);
        }
        return midIndex;

    }

    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 7, 9, 11, 13};
        int findVal = 13;
        int expectedIndex = arr.length - 1;
        int result = binary(arr, 0, arr.length - 1, findVal);
        System.out.println(result);
    }

}
